/*
 * MongoDB.h
 *
 *  Created on: 2013. 12. 3.
 *      Author: jjaehuny
 */

#ifndef PROJECTZ_NGAMELOG_MONGODB_H_
#define PROJECTZ_NGAMELOG_MONGODB_H_

#define MONGO_HAVE_STDINT 1
#include "../../N3rdParty/NMongo/mongo.h"
#include "../NUtil/ThreadPool.h"

#include <vector>
#include <mutex>

namespace ProjectZ { namespace NGameLog {
class Bson;

class MongoDB
{
public:
	class Wrapper
	{
	public:
		Wrapper(std::string ip, int port);
		~Wrapper();

		void					Execute(Bson * pbson);

	private:
		mongo 					_conn;
	};

public:
	MongoDB(int connectCount = 1);
	virtual ~MongoDB();


	void		Init(std::string ip , int port);
	void		Push(Bson * pBson);

private:
	void		work();

private:
//	std::vector<Bson*> 		_clsBsonVectorPost;
	std::deque<Bson*> 		_clsBsonVector;
	std::vector<Wrapper *>	_clsWrapperPool;
	NUtil::ThreadPool		_threadPool;

	std::mutex 				_mutex;
	int						_connectCount;
};

} /*NGameLog*/ } /*ProjectZ*/

#endif /* PROJECTZ_NGAMELOG_MONGODB_H_ */
